package com.bw.controller.system;

import com.alibaba.dubbo.config.annotation.Reference;
import com.bw.entity.PageResult;
import com.bw.entity.Result;
import com.bw.pojo.system.Admin;
import com.bw.pojo.system.AdminPassword;
import com.bw.pojo.system.Admins;
import com.bw.service.system.AdminService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Reference
    private AdminService adminService;

    @GetMapping("/findAll")
    public List<Admin> findAll(){
        return adminService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Admin> findPage(int page, int size){
        return adminService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Admin> findList(@RequestBody Map<String,Object> searchMap){
        return adminService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Admin> findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  adminService.findPage(searchMap,page,size);
    }

    @GetMapping("/findById")
    public Admin findById(Integer id){
        //查取中间表的数据，写入组合实体类中
        //查询admin管理员
        return adminService.findById(id);
    }
    @GetMapping("/findByName")
    public AdminPassword findByName(String name){
        return adminService.findByName(name);
    }

    @PostMapping("/updateAdmins")
    public Result updateAdmins(@RequestBody Admins admins){
        adminService.updateAdmins(admins);
        return new Result();
    }

    @GetMapping("/findAdminsById")
    public Admins findAdminsById(Integer id){
        //查取中间表的数据，写入组合实体类中
        //查询admin管理员
        return adminService.findAdminsById(id);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Admin admin){
        adminService.add(admin);
        Integer a = admin.getId();
        //将管理员id和角色id集合，循环存入tb_admin_role中
        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Admin admin){
        //删除中间表数据

        //将新设置角色数据添加

        adminService.update(admin);
        return new Result();
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        adminService.delete(id);
        return new Result();
    }

    @PostMapping("updatePassword")
    public Result updatePassword(@RequestBody AdminPassword adminPassword){
        adminService.updatePassword(adminPassword);
        return new Result();
    }

}
